package com.lzb.newloan.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lzb.newloan.OverduePhoneActivity;
import com.lzb.newloan.R;
import com.lzb.newloan.pojo.BorrowPersonPojo;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;

public class OverdueListAdapter extends BaseAdapter {

	private ArrayList<BorrowPersonPojo> pojo;
	private LayoutInflater mInflater;
	private Context context;
	private int flag;

	public OverdueListAdapter(Context context, ArrayList<BorrowPersonPojo> pojo, int flag) {
		this.pojo = pojo;
		this.mInflater = LayoutInflater.from(context);
		this.context = context;
		this.flag = flag;
	}

	public ArrayList<BorrowPersonPojo> getArrayList() {
		return pojo;
	}

	public void setArrayList(ArrayList<BorrowPersonPojo> arrayList) {
		this.pojo = arrayList;
	}

	@Override
	public int getCount() {
		if (pojo == null) {
			return 0;
		} else {
			return pojo.size();
		}
	}

	@Override
	public Object getItem(int arg0) {

		return pojo.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int postition, View convertView, ViewGroup arg2) {
		ViewHoler viewHolder = null;
		if (convertView == null) {
			viewHolder = new ViewHoler();
			convertView = mInflater.inflate(R.layout.adapter_overdue_list, null);
			viewHolder.name = (TextView) convertView
					.findViewById(R.id.name);
			viewHolder.jk_date = (TextView) convertView.findViewById(R.id.jk_date);
			viewHolder.money = (TextView) convertView.findViewById(R.id.money);
			viewHolder.hk_date = (TextView) convertView.findViewById(R.id.hk_date);
			viewHolder.lx = (TextView) convertView
					.findViewById(R.id.lx);
			viewHolder.overdue_days = (TextView) convertView.findViewById(R.id.overdue_days2);
			viewHolder.icon_img = (ImageView) convertView.findViewById(R.id.icon_img);
			viewHolder.cuishou = (TextView) convertView.findViewById(R.id.cuishou);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHoler) convertView.getTag();
		}
		final BorrowPersonPojo data = pojo.get(postition);
		viewHolder.name.setText(data.getUsername());
		viewHolder.lx.setText("利息:" + data.getLx());
		viewHolder.money.setText("本金:"+data.getSp_money());
		viewHolder.jk_date.setText("借款日:" + data.getTime());
		viewHolder.hk_date.setText("还款日:"+data.getFkTime());
		viewHolder.overdue_days.setText(data.getDay());

		ImageLoader.getInstance().displayImage(data.getLiving_photo(),viewHolder.icon_img);

		viewHolder.cuishou.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(context, OverduePhoneActivity.class);
				intent.putExtra("id", data.getId());
				context.startActivity(intent);
			}
		});
		return convertView;
	}

	public class ViewHoler {
		private ImageView icon_img;
		public TextView jk_date,name, money, lx, hk_date,overdue_days,cuishou;
	}

}
